package controller;


import Utils.dateUtil;
import com.smart.domain.Express;
import com.smart.infer.userPubInt;
import com.smart.service.selectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.export.notification.UnableToSendNotificationException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

@Controller
public class SelectController {
    @Autowired
    private selectService s;
    @Autowired
    private userPubInt mapper;

    @RequestMapping("selCN.html")//查询菜鸟快递
    public ModelAndView SelectCN(HttpServletRequest request)throws UnsupportedEncodingException {
        request.setCharacterEncoding("utf-8");
        String id = (String) request.getSession().getAttribute("userid");
        List<Express> list= mapper.findByEsc("中通",id);
        List<Express> list2= mapper.findByEsc("圆通",id);
        List<Express> list3= mapper.findByEsc("韵达",id);
        List<Express> list4= mapper.findByEsc("天天",id);
        List<Express> List=new ArrayList<>();
        List.addAll(list);List.addAll(list2);List.addAll(list3);List.addAll(list4);
        dateUtil dateutil=new dateUtil();
        List List2=dateutil.changeStatus(List);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name","菜鸟驿站");
        modelAndView.addObject("list",List2);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }

    @RequestMapping("selYZ.html")//查询邮政快递
    public ModelAndView selectYZ(HttpServletRequest request)throws UnsupportedClassVersionError{
        String id = (String)request.getSession().getAttribute("userid");
        List<Express> listYZ=mapper.findByEsc("邮政",id);
        dateUtil dateutil=new dateUtil();
        List listyz=dateutil.changeStatus(listYZ);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","邮政");
        modelAndView.addObject("list",listyz);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
    @RequestMapping("selJD.html")//查询京东快递
    public ModelAndView selectJD(HttpServletRequest request)throws UnsupportedClassVersionError{
        String id = (String)request.getSession().getAttribute("userid");
        List<Express> listJD=mapper.findByEsc("京东",id);
        dateUtil dateutil=new dateUtil();
        List listjd=dateutil.changeStatus(listJD);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","京东");

        modelAndView.addObject("list",listjd);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
    @RequestMapping("selTM.html")//查询天猫快递
    public ModelAndView selectTM(HttpServletRequest request)throws UnsupportedClassVersionError{
        String id = (String)request.getSession().getAttribute("userid");
        List<Express> listTM=mapper.findByEsc("天猫",id);

        dateUtil dateutil=new dateUtil();
        List listtm=dateutil.changeStatus(listTM);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","天猫");

        modelAndView.addObject("list",listtm);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
    @RequestMapping("selST.html")//查询申通快递
    public ModelAndView selectST(HttpServletRequest request)throws UnsupportedClassVersionError{
        String id = (String)request.getSession().getAttribute("userid");
        List<Express> listST=mapper.findByEsc("申通",id);

        dateUtil dateutil=new dateUtil();
        List listst=dateutil.changeStatus(listST);

        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","申通");

        modelAndView.addObject("list",listst);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
    @RequestMapping("selBS.html")//查询百世快递
    public ModelAndView selectBS(HttpServletRequest request)throws UnsupportedClassVersionError{
        String id = (String)request.getSession().getAttribute("userid");
        List<Express> listBS=mapper.findByEsc("百世",id);

        dateUtil dateutil=new dateUtil();
        List listbs=dateutil.changeStatus(listBS);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("name","百世");

        modelAndView.addObject("list",listbs);
        modelAndView.setViewName("leadExpress");
        return modelAndView;
    }
}
